/*
 *基本规则：
 * 1. 分享即开店、上架
 * 2. 无来源用户交易即开店
 * 3. 一级分销看来源
 * 4. 用户上下级（注册）
 */
<script>
	import util from 'common/util.js'
	import common from 'common/common.js'
	import {mapMutations} from 'vuex'
	export default {
		onLaunch: function() {
			console.log('App Launch')
			this.global.apiUrl = util.getApiUrl()
			this.getUser()
		},
		onShow: function() {
			console.log('App Show')
			this.getNetWork()
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			...mapMutations(['login','setLoginType','setUserId','setOpenid','setIsShop','setUserInfo','setShopId','setUnionId','setFId','setUserFId','setNetworkType','setShopStatus']),
			getUser(){
				var that = this
				uni.getSetting({
				    success: res => {
				        console.log(res)
				        if (res.authSetting['scope.userInfo']) {
							uni.getUserInfo({
								success: res => {
									console.log(res)
									that.setUserInfo(res.userInfo)
								}
							})
				        }
				    }
				})
				// 登录
				uni.login({
					success:function(login){
						console.log(login)
						// 发送请求
						uni.request({
							url: that.global.apiUrl + '/get_openid', //接口地址
							data: {
								code: login.code
							},
							method: 'get',
							header: {
								'content-type': 'application/json' //默认值
							},
							success: function (res) {
								console.log(res)
								//判断用户是否存在
								if(res.data.code == '1'){
									//后台有数据
									that.setUserId(res.data.data.id)
									that.setIsShop(res.data.data.is_shop)
									that.setShopId(res.data.data.user_shop_id)
									that.setOpenid(res.data.data.openid)
									if(res.data.data.unionid){
										that.login(that.$store.state)
									}else{
										that.setLoginType(2)
									}
									that.setUnionId(res.data.data.unionid)
									that.setFId(res.data.data.fid)
									that.setUserFId(res.data.data.user_fid)
									that.setShopStatus(res.data.data.shop_status)
								}else if(res.data.code == '0'){
									that.setOpenid(res.data.data.openid)
									that.setUnionId(res.data.data.unionid)
									that.setLoginType(1)
								}
							}
						})
					}
				})
				uni.getSystemInfo({
					success: res=>{
					// console.log('手机信息res'+res.model)
						console.log(res);
						let modelmes = res.model;
						if (modelmes.search('iPhone X') != -1) {
							that.global.isIphoneX = true
						}
						that.global.screenHeight = res.screenHeight
					}
				})
				var isGoodsGuide = uni.getStorageSync("isGoodsGuide")
				if(isGoodsGuide == ''){
					uni.setStorageSync('isGoodsGuide','true')
				}
			},
			getNetWork(){
				uni.getNetworkType({
					success: (res) => {
						console.log(res);
						this.setNetworkType(res.networkType)
						if(res.networkType == 'none'){
							util.showModal('提示','网络连接失败，请重新连接网络');
						}
					}
				})
				// 监听网络状态变化
				uni.onNetworkStatusChange((res)=>{
					console.log(res);
					this.setNetworkType(res.networkType)
					if(!res.isConnected){
						util.showModal('提示','网络连接失败，请重新连接网络');
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	page{
		@include backG($pageBg);
	}
	.container {
	  height: 100%;
	  display: flex;
	  flex-direction: column;
	  @include flex-align-justify(center,space-between)
	  box-sizing: border-box;
	}
	.calc{
	  width: calc(100% - 50rpx);
	  @include margin(0 auto);
	}
	.display{
	  display: -webkit-box;
	  display: -webkit-flex;
	  display: -ms-flexbox;
	  display: flex;
	}
	.display_1{
	  -webkit-box-flex: 1;
	  -webkit-flex: 1;
	  -ms-flex: 1;
	  flex: 1;
	}
	.flow{
		flex-flow: row nowrap;
		@include flex-align-justify(center,space-between)
	}
	.column{
		flex-direction: column;
	}
	button{
		margin: 0;
		padding: 0;
		border: 1px solid transparent;  //自定义边框
		outline: none;    //消除默认点击蓝色边框效果
		background: none;
	}
	button::after{
		border: none;
	}
	.fontHide{
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
	.fontHide2{
		overflow: hidden;
		display: -webkit-box;
		text-overflow: ellipsis;
		-webkit-line-clamp: 2;  /*要显示的行数*/
		-webkit-box-orient: vertical;
	}
	.priceAre{
		@include flex-align-justify(flex-end,flex-start)
		.price{
			@include font($fontSize + 6rpx);
			@include margin(10rpx,'right');
		}
		.pColor{
			color: $greyColor;
			text-decoration: line-through;
		}
	}
	.price{
		color: $redColor;
	}
	.borderR{
		@include borderR(20rpx);
	}
	.lineColor{
		background: $grey;
	}
	.pColor{
		@include font($fontSize - 2rpx,$greyColor);
	}
	.borderB{
		@include border(2rpx,$borderBg,'bottom');
	}
	.topFixed{
		position: fixed;
		top: calc(var(--window-top));
		z-index: 99;
	}
	.topFixed2{
		position: fixed;
		top: calc(var(--status-bar-height));
		z-index: 99;
	}
	.carImg{
		@include widthHeight(35rpx);
	}
	.bottom{
		position: fixed;
		bottom: 0;
		z-index: 99;
	}
	@supports (bottom: constant(safe-area-inset-bottom)) or (bottom: env(safe-area-inset-bottom)){
		.bottom{
			bottom: calc(var(--window-bottom) + constant(safe-area-inset-bottom));
			bottom: calc(var(--window-bottom) + env(safe-area-inset-bottom));
		}
	}
	.earnings{
		@include backG($blackColor,$pinkColor);
		@include font($fontSize - 4rpx);
		@include padding(10rpx 20rpx);
		@include borderR(0 30rpx 30rpx 0);
		opacity: 0.9;
		@include text-align;
	}
	.pinkColor{
		color: $pinkColor;
	}
	.goldenColor{
		color: $goldenColor;
	}
	.orderBtn{
		@include width(140rpx);
		@include height(50rpx);
		@include font($fontSize - 4rpx);
		@include borderR(25rpx);
	}
	.themeBgColor{
		@include backG($themeColor,white);
	}
	.themeBdColor{
		@include border(2rpx,$themeColor);
		color: $themeColor;
	}
	.themeColor{
		color: $themeColor;
	}
	.navBg{
		@include widthHeight(750rpx,200rpx);
		z-index: -1;
		position: absolute;
		top: 0;
		left: 0;
		@include borderR(0 0 30rpx 30rpx);
		background: $themeColor;
	}
</style>
